package net.simflow.swf.analyzer.bgnetwork.stats.opt;

import java.util.HashMap;

import net.simflow.swf.analyzer.bgnetwork.data.BGNetwork;
import net.simflow.swf.analyzer.bgnetwork.data.BGNode;
import net.simflow.swf.analyzer.bgnetwork.stats.data.BGNetworkStats;
import net.simflow.swf.analyzer.network.data.Flow;
import net.simflow.swf.analyzer.network.data.Service;

public class BGNetworkStatsAnalyzer {

	private static BGNetworkStatsAnalyzer instance = new BGNetworkStatsAnalyzer();

	private BGNetworkStatsAnalyzer() {
	}

	public static BGNetworkStatsAnalyzer getInstance() {
		return instance;
	}

	public BGNetworkStats analyze(BGNetwork network,
			HashMap<Flow, BGNode> flowNetwork,
			HashMap<Service, BGNode> serviceNetwork) {
		BGNetworkStats bgnStats = new BGNetworkStats();

		bgnStats.setNetwork(network);
		bgnStats.setNetworkName(network.getName());
		bgnStats.setNetworkFlowDegreeDistribution(BGNetworkDegreeDistributionAnalyzer
				.getInstance().analyzeFlowDegreeDistribution(network));
		bgnStats.setNetworkServiceDegreeDistribution(BGNetworkDegreeDistributionAnalyzer
				.getInstance().analyzeServiceDegreeDistribution(network));
		bgnStats.setNetworkFlowNeighborMap(BGNetworkNeighborAnalyzer
				.getInstance().analyzeNetworkFlowNeighbor(network));
		bgnStats.setNetworkServiceNeighborMap(BGNetworkNeighborAnalyzer
				.getInstance().analyzeNetworkServiceNeighbor(network));

		bgnStats.setFlowNetwork(flowNetwork);
		bgnStats.setFlowNetworkName(network.getName() + " Flow");
		bgnStats.setFlowNetworkDegreeDistribution(BGNetworkDegreeDistributionAnalyzer
				.getInstance().analyzeDegreeDistribution(flowNetwork.values()));
		bgnStats.setFlowNeighborMap(BGNetworkNeighborAnalyzer.getInstance()
				.analyzeNeighbor(flowNetwork.values()));

		bgnStats.setServiceNetwork(serviceNetwork);
		bgnStats.setServiceNetworkName(network.getName() + " Service");
		bgnStats.setServiceNetworkDegreeDistribution(BGNetworkDegreeDistributionAnalyzer
				.getInstance().analyzeDegreeDistribution(
						serviceNetwork.values()));
		bgnStats.setServiceNeighborMap(BGNetworkNeighborAnalyzer.getInstance()
				.analyzeNeighbor(serviceNetwork.values()));

		return bgnStats;
	}
}
